﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StableDiffusionTools.Animation
{
    public class Frame : IDisposable
    {
        public int Duration { get; private set; }
        public Bitmap Image { get; private set; }
        public int Width { get => Image.Width; }
        public int Height { get => Image.Height; }

        public Frame(int duration, Bitmap image)
        {
            Duration = duration;
            Image = image;
        }

        #region IDisposable
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if(Image != null)
                    {
                        Image.Dispose();
                        Image = null;
                    }
                }
                disposedValue = true;
            }
        }

        // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
        // ~Frame() {
        //   // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
        //   Dispose(false);
        // }

        // This code added to correctly implement the disposable pattern.
        public void Dispose()
        {
            // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
            Dispose(true);
            // TODO: uncomment the following line if the finalizer is overridden above.
            // GC.SuppressFinalize(this);
        }
        #endregion

        public IntPtr GetHbitmap()
        {
            return Image.GetHbitmap();
        }
    }
}
